import java.util.concurrent.CountDownLatch;

/**
 * @author wcj
 * @Date 2021/6/17 15:40
 * @Version 1.0
 */
public class CountDownLatchTest {

    static CountDownLatch countDownLatch = new CountDownLatch(2);

    /**
     * CountDownLatch：功能类似于Join()
     * join()：是让当前线程等待调用join的线程执行完毕之后再执行
     * CountDownLatch：让一个或者多个线程等待其它线程执行完毕
     * 初始化时传入整型作为构造器，但是注意构造器值不能进行重置
     *
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
                countDownLatch.countDown();
                System.out.println(2);
                countDownLatch.countDown();
            }
        }).start();

        countDownLatch.await();

        System.out.println(3);
    }
}
